package com.hhxy.practice;

import java.util.Scanner;
//计算飞机票的实际价格
public class ByTicket {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double price;
        String type;
        int month;
        do {
            System.out.println("请您输入机票的原价");
            price =  sc.nextDouble();

            System.out.println("请输入机舱类型：头等舱 or 经济舱");
            type = sc.next();//使用nextLine会报异常

            System.out.println("请输入月份信息：1~12月");
            month = sc.nextInt();
            }while(calc(price, type, month)==-1);
        System.out.println("您需要支付" + calc(price, type, month) + "￥");
        }

    private static double calc(double price,String type,int month){
        if(type.equals("头等舱")){
            if(5<=month && month<=10){
                price *= 0.9;
            }else if((1<=month && month<=4) || (11<=month && month<=12)){
                price *= 0.7;
            }else{
                System.out.println("对不起您输入的月份不对，请重新输入");
                return -1;
            }
        }else if(type.equals("经济舱")){
            if(5<=month && month<=10){
                price *= 8.5;
            }else if((1<=month && month<=4) || (11<=month && month<=12)){
                price *= 6.5;
            }else{
                System.out.println("对不起您输入的月份不对，请重新输入");
                return -1;
            }
        }else{
            System.out.println("对不起您输入的机舱类型不存在，请重新输入！");
            return -1;
        }
        return price;
    }
}
